﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.Common;

using SimpleService.ORM;

namespace testORM
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            DataSet ds = SqlOperator.ExecuteDataset(DbConfig.connectionString, CommandType.Text, "select * from Users");

            DbOperation dbo = new DbOperation(DbConfig.dbType);
            
            Response.Write(ds.Tables[0].Rows[0]["uid"].ToString());
            Response.Write(ds.Tables[0].Rows[0]["password"].ToString());

            Response.Write("<br>");

            DbConnection connection = dbo.GetConnection(DbConfig.connectionString);
            connection.Open();
            PersistenceObject functions = PersistenceObject.select(connection, "functions");

   


            //欄位數
            Response.Write("欄位數：");
            Response.Write(functions.ColsCount);
            Response.Write("<br>");

            //資料筆數
            Response.Write("資料筆數：");
            Response.Write(functions.RowsCount);
            Response.Write("<br>");



            //抓出第一筆的「fid欄位」資料
            Response.Write("<br>抓出第一筆的「fid欄位」資料：<br>");

            //方法一
            Response.Write(functions.Rows[0]["fid"]);
            Response.Write("<br>");

            //方法二
            Response.Write(functions.Rows[0][0]);
            Response.Write("<br>");

            //方法三
            Response.Write(functions.Rows["fid"]);
            Response.Write("<br>");





            //抓出第二筆的「classname欄位」資料
            Response.Write("<br>抓出第二筆的「title欄位」資料：<br>");

            //方法一
            Response.Write(functions.Rows[1]["title"]);
            Response.Write("<br>");

            //方法二
            Response.Write(functions.Rows[1][1]);
            Response.Write("<br>");


            //抓出全部每一筆的「fid欄位」
            Response.Write("<br>抓出全部「fid欄位」：<br>");
            foreach (strings 輸出 in functions.Rows)
            {
                Response.Write(輸出["fid"]);
                Response.Write("<br>");
            }



            //抓出第一筆資料的每個欄位
            Response.Write("<br>抓出第一筆資料的每個欄位：<br>");

            //方法一(for)
            Response.Write("<br>方法一(for)<br>");
            for (int i = 0; i < functions.RowsCount; i++)
            {
                Response.Write(functions.Rows[0][i]);
                Response.Write("<br>");
            }

            //方法二(foreach)
            Response.Write("<br>方法二(foreach)<br>");
            foreach (string 輸出 in functions.Rows[0])
            {
                Response.Write(輸出);
                Response.Write("<br>");
            }


            //抓出每筆資料的每個欄位
            Response.Write("<br>抓出每筆資料的每個欄位：<br>");

            //方法一(for)
            Response.Write("<br>方法一(for)<br>");
            for (int i = 0; i < functions.RowsCount; i++)
            {
                for (int j = 0; j < functions.ColsCount; j++)
                {
                    Response.Write(functions.Rows[i][j]);
                    Response.Write("<br>");
                }
            }

            //方法二(foreach)
            Response.Write("<br>方法二(foreach)<br>");
            foreach (strings 輸出 in functions.Rows)
            {
                foreach (string 結果 in 輸出)
                {
                    Response.Write(結果);
                    Response.Write("<br>");
                }
            }


            Response.Write("「insert動作：Table qqqqqq = Table.insert(connection,\"sampletable\", \"pompompom\");」");
            Response.Write("<br>");
            Response.Write("<br>");
            //insert(若是已經存在會抓到,不存在會INSERT)
            PersistenceObject qkomljlkomjikqqqqq = PersistenceObject.insert(connection, "functions", "pompompom"); //代入主鍵

            qkomljlkomjikqqqqq.Rows["title"] = "測測看";
            
            qkomljlkomjikqqqqq.Rows.delete = true;


           // PersistenceObject.delete(connection, "functions", "pompompom"); //代入主鍵

            //Response.Write(qkomljlkomjikqqqqq9.RowsCount);

            connection.Close();

 

        }
    }
}